<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../templates/StakeholderPortalTemplate.xhtml">

    <ui:define name="content"> 
            <h:form id="mainForm">
                <h1>Validate a voucher</h1>

                <p:fieldset style="width:950px">

                    <p:ajaxStatus style="width:16px;height:16px;">
                        <f:facet name="start">
                            <h:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" />
                        </f:facet>
                        <f:facet name="complete">
                            <h:outputText value="" />
                        </f:facet>
                    </p:ajaxStatus>
                    <p:fieldset>
                        <p:message id="referenceNumberMsg" for="referenceNumber" />
                        <h:panelGrid columns="3" columnClasses="column" cellpadding="5">
                            <h:outputText value="Enter groupon voucher's reference number: " style="font-weight:bold; text-align:center; font-size:12px" />
                            <p:inputText required="true" requiredMessage="Voucher's reference number is required." id="referenceNumber" value="#{grouponManagerBean.inputReferenceNumber}">
                                <p:ajax event="blur" update="referenceNumberMsg" />
                            </p:inputText>
                            <p:commandButton id="submitbutton" value="Validate" update="mainForm" actionListener="#{grouponManagerBean.stakeholderValidateVoucher}" ajax="true" />

                        </h:panelGrid>
                        
                    </p:fieldset>
                    <p:messages/>
                    <br/>
                    <br/>    
                    <p:fieldset rendered="#{grouponManagerBean.voucherExist}">
                        <h2>VOUCHER'S DETAIL</h2>
                        <h:panelGrid columns="2" border="1" columnClasses="column" cellpadding="5">
                            <h:panelGrid columns="2" border="1" columnClasses="column" cellpadding="5">
                                <h:outputText value="Status: " style="font-weight:bold; text-align:center; font-size:14px"/>
                                <h:outputText value="#{grouponManagerBean.returnVoucherStatus(grouponManagerBean.selectedVoucher)}"  style="font-weight:bold; text-align:center; font-size:14px"/>

                                <h:outputText value="Groupon Reference Number: " style="font-weight:bold; text-align:center; font-size:12px" />
                                <h:outputText value="#{grouponManagerBean.selectedVoucher.referenceNumber}" />

                                <h:outputText value="Groupon name: " style="font-weight:bold; text-align:center; font-size:12px" />
                                <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.name}" />

                                <h:outputText value="Offered by: " style="font-weight:bold; text-align:center; font-size:12px"/>
                                <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.corpName}"/>

                                <h:outputText value="Valid From:" style="font-weight:bold; text-align:center; font-size:12px"/>
                                <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.startValidDate}">
                                    <f:convertDateTime dateStyle="full" pattern="EEE, dd/MM/yyyy" timeZone="EST" type="date" />
                                </h:outputText>

                                <h:outputText value="Valid Until: " style="font-weight:bold; text-align:center; font-size:12px"/>
                                <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.endValidDate}">
                                    <f:convertDateTime dateStyle="full" pattern="EEE, dd/MM/yyyy" timeZone="EST" type="date" />
                                </h:outputText>


                            </h:panelGrid>
                            <p:graphicImage id="imageDisplay" value="/images/upload/media/#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.imageURL}"
                                            height="300" width="450"/> 
                        </h:panelGrid>
                    </p:fieldset>
                    <br/> 

                    <p:fieldset legend="Company's contact details" toggleable="true" toggleSpeed="500"
                                onToggleUpdate="growl" style="width:900px" rendered="#{grouponManagerBean.voucherExist}">
                        <h:panelGrid columns="2" columnClasses="column" cellpadding="5">
                            <h:outputText value="Company name: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.corpName}" />

                            <h:outputText value="Phone number: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.corpContactNumber}" />

                            <h:outputText value="Email address: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.corpEmail}" />

                            <h:outputText value="Office number: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.address.houseNumber}" />

                            <h:outputText value="Building name: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.address.buildingName}" />

                            <h:outputText value="Street name: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.address.streetName}" />

                            <h:outputText value="Postal code: " />
                            <h:outputText value="#{grouponManagerBean.selectedVoucher.purchasedGroupon.groupon.stakeholder.address.postalCode}" />

                        </h:panelGrid>
                    </p:fieldset>

                </p:fieldset>
                <br/>
                <p:confirmDialog message="Do you want to declare this groupon voucher as USED ?"
                                 showEffect="bounce" hideEffect="explode"
                                 header="Declare groupon voucher as USED" severity="alert" widgetVar="confirmation">

                    <p:commandButton value="Yes Sure" update="messages" oncomplete="confirmation.hide()"
                                     actionListener="#{grouponManagerBean.declareVoucherAsUsed}" />
                    <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" /> 

                </p:confirmDialog>
            </h:form>
    </ui:define>
</ui:composition>


